<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新建登记公司')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form id="form-compRegister-add" class="form-horizontal">
        <input name="regby" type="hidden" id="regby"/>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>公司代码：</label>
                    <div class="col-sm-8">
                        <input name="compCode" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')"   id="compCode" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>公司名称：</label>
                    <div class="col-sm-8">
                        <input name="title" id="title" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>公司简称：</label>
                    <div class="col-sm-8">
                        <input name="compAbbr" id="compAbbr" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>公司级别：</label>
                    <div class="col-sm-8">
                        <select name="compGrade" id="compGrade" class="form-control m-b"
                                th:with="type=${@dict.getType('oCD_CompGrade')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>公司类型：</label>
                    <div class="col-sm-8">
                        <select name="compType" id="compType" class="form-control m-b"
                                th:with="type=${@dict.getType('oCD_CompType')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select></div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>所属行业：</label>
                    <div class="col-sm-8">
                        <select name="industy" id="industy" class="form-control m-b"
                                th:with="type=${@dict.getType('oCD_CompIndustri')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>公司区域：</label>
                    <div class="col-sm-8">
                        <select name="compArea" id="compArea" class="form-control m-b"
                                th:with="type=${@dict.getType('oCD_CompArea')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select></div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>上级公司：</label>
                    <div class="col-sm-8">
                        <select id="adminId" name="adminId" class="form-control" required>
                            <option value="0"></option>
                            <option th:each="companys:${companys}" th:value="${companys.compID }"
                                    th:text="${companys.compAbbr }"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"></span>法人代表：</label>
                    <div class="col-sm-8">
                        <input name="lawyer" id="lawyer" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"></span>公司地址：</label>
                    <div class="col-sm-8">
                        <input name="address" id="address" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"></span>注册地址：</label>
                    <div class="col-sm-8">
                        <input name="regAddress" id="regAddress" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"></span>联系电话：</label>
                    <div class="col-sm-8">
                        <input name="tel" id="tel" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"></span>邮政编码：</label>
                    <div class="col-sm-8">
                        <input name="postCode" id="postCode" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"></span>公司网站：</label>
                    <div class="col-sm-8">
                        <input name="webSite" id="webSite" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"></span>统一社会信用代码：</label>
                    <div class="col-sm-8">
                        <input name="socialCreCode" id="socialCreCode" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"></span>企业资质：</label>
                    <div class="col-sm-8">
                        <input name="enterpriseQuafic" id="enterpriseQuafic" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"></span>公司简介：</label>
                    <div class="col-sm-8">
                        <input name="companyProfile" id="companyProfile" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>成立日期：</label>
                    <div class="col-sm-8">
                        <input name="effectDate" id="effectDate" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"></span>备注：</label>
                    <div class="col-sm-8">
                        <input name="remark" id="remark" class="form-control" type="text">
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: datetimepicker-js"/>


<script>
    var prefix = ctx + "company/admin";
    $(function () {
        $("#effectDate").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    });

    function submitHandler() {

        var compGrade = $("#compGrade").val();
        var adminId = $("#adminId").val();

        if (compGrade == 6) {
            if (adminId != 0) {
                $.modal.alertWarning('一级公司不能有上级公司！')
                return;
            }
        }

        if (compGrade != 6) {
            if (adminId == 0) {
                $.modal.alertWarning('非一级公司必须选择上级公司！')
                return;
            }
        }

        if ($.validate.form()) {
            var data = $("#form-compRegister-add").serializeArray();
            var compCode = $("#compCode").val();
            var title = $("#title").val();
            var compAbbr = $("#compAbbr").val();
            var compType = $("#compType").val();
            var industy = $("#industy").val();
            var compArea = $("#compArea").val();
            var lawyer = $("#lawyer").val();
            var address = $("#address").val();
            var regAddress = $("#compCode").val();
            var tel = $("#tel").val();
            var postCode = $("#postCode").val();
            var webSite = $("#webSite").val();
            var socialCreCode = $("#socialCreCode").val();
            var enterpriseQuafic = $("#enterpriseQuafic").val();
            var companyProfile = $("#companyProfile").val();
            var effectDate = $("#effectDate").val();
            var remark = $("#remark").val();

            data.push({"id": "compCode", "value": compCode});
            data.push({"id": "title", "value": title});
            data.push({"id": "compAbbr", "value": compAbbr});
            data.push({"id": "compGrade", "value": compGrade});
            data.push({"id": "compType", "value": compType});
            data.push({"id": "industy", "value": industy});
            data.push({"id": "compArea", "value": compArea});
            data.push({"id": "adminId", "value": adminId});
            data.push({"id": "lawyer", "value": lawyer});
            data.push({"id": "address", "value": address});
            data.push({"id": "regAddress", "value": regAddress});
            data.push({"id": "tel", "value": tel});
            data.push({"id": "postCode", "value": postCode});
            data.push({"id": "webSite", "value": webSite});
            data.push({"id": "socialCreCode", "value": socialCreCode});
            data.push({"id": "enterpriseQuafic", "value": enterpriseQuafic});
            data.push({"id": "companyProfile", "value": companyProfile});
            data.push({"id": "enterpriseQuafic", "value": enterpriseQuafic});
            data.push({"id": "effectDate", "value": effectDate});
            data.push({"id": "remark", "value": remark});
            $.operate.saveTab(prefix + "/add/register", data);
        }
    }

</script>


</body>
</html>